<?php include_once 'header.php'; ?>
<aside class="right-side">
    <section class="content-header">
        <h1>
            Terms & Conditions
            <small>Content Management</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-file-o"></i> Content Management</a></li>
            <li class="active">Terms & Conditions</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box box-solid">
                    <div class="box-header">
                        <i class="fa fa-text-width"></i>
                        <i id="edit-terms-btn" style="float: right;margin-right: 15px;cursor:pointer" class="fa fa-pencil-square-o"></i>
                    </div>
                    <!-- /.box-header -->
                    <div id="content-area" class="box-body">

                    </div>
                </div>
            </div>
        </div>
    </section>
</aside>

<div class="modal fade" id="myTerms" tabindex="-1" role="dialog" aria-labelledby="myTermsLabel" aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog" style="width: 800px !important;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myMailLabel">Add/Edit Terms & Conditions</h4>
            </div>
            <div class="modal-body">
                <form id="termsForm" action="#" method="post">
                    <input type="hidden" name="content-id" id="content-id"/>
                    <textarea class="editor" placeholder="Terms and Conditions" name="content-description" id="content-description"
                              style="width: 100%; height: 300px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" id="saveTerms">Save</button>
                <button type="button" class=" pull-right btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<?php include 'footer.php'; ?>
<script>
    $(document).ready(function () {
        $.get("getContent/TERMS", function (response) {
            if (!response.error) {
                if (response.data == "" || response.data == null) {
                    $("#myTerms").modal("show");
                } else {
                    $("#content-area").html(response.data[0].description);
                    $("#content-id").val(response.data[0].id);
                    $("#content-description").data("wysihtml5").editor.setValue(response.data[0].description);
                }
            } else {
                errorAlert(response.errorMessage);
            }
        })

        $("#saveTerms").click(function(){
            $("#myTerms").modal("hide");
            $.post("saveContent/TERMS", $("#termsForm").serialize(), function(response){
                if (!response.error) {
                    $("#content-area").html(response.data.description);
                    $("#content-id").val(response.data.id);
                    $("#content-description").val(response.data.description);
                }else {
                    errorAlert(response.errorMessage);
                }
            });
        });

        $("#edit-terms-btn").click(function(){
            $("#myTerms").modal("show");
        });
    });
</script>